using System;

namespace VirtualKeyboard.Service.Commands
{
    public static class ShortcutKeyConvert
    {
        public static Keys[] Convert(string shortcutKey)
        {
            var keyValues = Parse(shortcutKey);
            var result = new Keys[keyValues.Length];
            for (int i = 0, length = keyValues.Length; i < length; i++)
            {
                var keyVaule = keyValues[i];
                Keys key;
                bool success = Enum.TryParse(keyVaule, false, out key);
                if (success)
                {
                    result[i] = key;
                }
            }
            return result;
        }

        private static string[] Parse(string shortcutKey)
        {
            string[] result = shortcutKey.Split('+');
            for (int i = 0, length = result.Length; i < length; i++)
            {
                result[i] = result[i].Trim(' ');
            }
            return result;
        }
    }
}